
package com.ami.kvm.isocaching;

import java.util.NoSuchElementException;

public class CacheManager extends Thread {
	public static final int MAX_FREE_BANKS_COUNT = 128;
	private ReadAheadCache readAheadCache = null;
	private int freeBankCount = 256;
	private boolean running = false;
	private boolean sortCache = false;
	private boolean cleanUpCache = false;

	public CacheManager(ReadAheadCache paramReadAheadCache) {
		this.readAheadCache = paramReadAheadCache;
	}

	public void run() {
		while (this.running) {
			synchronized (this.readAheadCache.getCacheLock()) {
				if (isCleanUpCache()) {
					this.readAheadCache.setCacheLocked(true);
					cleanUpCache();
					this.readAheadCache.setCacheLocked(false);
					this.readAheadCache.getCacheLock().notifyAll();
					setCleanUpCache(false);
				}
				try {
					this.readAheadCache.getCacheLock().wait();
				} catch (InterruptedException localInterruptedException) {
				}
			}
		}
	}

	public void cleanUpCache() {
		int i = 0;
		while ((i < 128) && (this.readAheadCache.getSectorDataCache().size() > 0)) {
			try {
				((SectorBank) this.readAheadCache.getSectorDataCache().removeLast()).getSectorKey();
			} catch (NoSuchElementException localNoSuchElementException) {
				break;
			} catch (Exception localException) {
				break;
			}
			i++;
		}
		setFreeBankCount(i);
		System.gc();
	}

	public void startThread() {
		this.running = true;
		start();
	}

	public void stopThread() {
		this.running = false;
	}

	public int getFreeBankCount() {
		return this.freeBankCount;
	}

	public void setFreeBankCount(int paramInt) {
		this.freeBankCount = paramInt;
	}

	public boolean isRunning() {
		return this.running;
	}

	public void setRunning(boolean paramBoolean) {
		this.running = paramBoolean;
	}

	public boolean isSortCache() {
		return this.sortCache;
	}

	public void setSortCache(boolean paramBoolean) {
		this.sortCache = paramBoolean;
	}

	public boolean isCleanUpCache() {
		return this.cleanUpCache;
	}

	public void setCleanUpCache(boolean paramBoolean) {
		this.cleanUpCache = paramBoolean;
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\isocaching\CacheManager.
 * class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */